<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>用户管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			getBeSysUserId($("#beStoreCode").val());
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				rules:{          
					beStoreCode:{required:true},
					beSysUserId:{required:true},
					discount:{required:true,isPrice:true}
	            },
				messages:{
					beStoreCode:{required:"请选择所属门店"},
					beSysUserId:{required:"请选择所属业务人员"},
					storeList:{required:"请选择可下单门店"},
					discount:{required:"请输入折扣系数"}
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		function getBeSysUserId(value){
			if(value==""){
				$("#beSysUserId").html("<option value=''>--请选择 --</option>");
				$("#beSysUserIdDiv .select2-chosen").html("请选择");
			}else{
				$.ajax({
			        type : "post",
			        async : false,
			        url : "${ctx}/sys/commonUser/selectSaleByStore",
			        data : {'code' : value},
			        dataType : "json",
			        success : function(result) {
		        		$("#beSysUserId").html("<option value=''>--请选择 --</option>");
			        	if(result!=null){
							$.each(result, function(i,user){
			        			$("<option value='"+user.id+"'>"+user.name+"</option>").appendTo($("#beSysUserId"));
			        		});
			        	}
			        	var hiddenSala = $("#hiddenSala").val();
			        	$("#beSysUserId option[value='"+hiddenSala+"']").attr("selected","selected");
					}
				})
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/commonUser/vipUserInfoList">会员信息列表</a></li>
		<li class="active"><a href="${ctx}/sys/commonUser/vipUserInfoStore?id=${yongUser.id}">门店设置</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="yongUser" action="${ctx}/sys/commonUser/saveVipUserInfoStore" method="post" class="form-horizontal">
		<div style="display:none;">
			<sys:message content="${message}"/>
		</div>
		<input type="hidden" value="${yongUser.id }" name="id">	
		<div class="control-group">
			<label class="control-label">所属门店：</label>
			<div class="controls">
				<form:select path="beStoreCode" class="input-medium required" onchange="getBeSysUserId(this.value)">
					<form:option value="" label="请选择"/>
					<form:options items="${sysUserStores}" htmlEscape="false" itemValue="code" itemLabel="cnName"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">所属业务人员：</label>
			<div class="controls" id="beSysUserIdDiv">
				<input type="hidden" value="${sala.id}" id="hiddenSala">
				<form:select path="beSysUserId" class="input-medium" id="beSysUserId">
				<c:if test="${sala!=null }">
					<form:option value="${sala.id }" label="${sala.name}" />
				</c:if>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">可下单门店：</label>
			<div class="controls">
				<sys:storetypeselectForUser  id="storeList" name="storeList" value="${yongUser.storeName}" userId="${yongUser.id}" checks="${yongUser.storeIdList}" checkedList="${yongUser.storeList }"  url="${ctx}/sys/commonUser/selectAllStoreListByType?userId=${yongUser.id}"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">折扣系数：</label>
			<div class="controls">
				<form:input path="discount" class="required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<div class="controls">
				<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
				<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
			</div>
		</div>
		<label style="font-weight: bold;">门店历史记录</label>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>所属门店</th>
				<th>所属业务人员</th>
				<th>可下单门店</th>
				<th>折扣系数</th>
				<th>最近修改日期</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="userEditHistroy">
			<tr>
				<td>${userEditHistroy.beStoreCnName}</td>
				<td>${userEditHistroy.sysUserName }</td>
				<td>${userEditHistroy.orderStoreCnName }</td>
				<td>${userEditHistroy.discount }</td>
				<td><fmt:formatDate value="${userEditHistroy.createDate}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	</form:form>
</body>
</html>